gdksurface-win32.c: Fix up popup placement
authorChun-wei Fan <fanchunwei@src.gnome.org>
Wed, 16 Jun 2021 04:24:47 +0000 (12:24 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Wed, 16 Jun 2021 08:25:29 +0000 (16:25 +0800)
If we are undergoing a surface move, just apply the next_layout anyways,
even if we are not moving a toplevel surface.

Update the way how we obtain the x and y coordinates of a surface, if it
is a toplevel, apply the x and y coordinates from the results from we
obtained the underlying Win32 HWND, as we did before.  But if it is a
popup, use gdk_win32_surface_get_geometry() to obtain the correct x and
y coordinates to place our popup surface.

Also correct how we compute the shadow dimensions, and the final popup
rectangle as we attempt to layout the popup surface, since GDK-Win32
keeps track of the shadow dimensions in system (unscaled) units, not GDK
units.

Fixes issue #3793.

gdk/win32/gdksurface-win32.c

index 3c5a42586125eb78bb0e9c469c564d0085e26a7e..bca73c6edb0b12fd9e5dfb6143fb713d843e927f 100644 (file)
@@ -1229,6 +1229,7 @@ gdk_win32_surface_layout_popup (GdkSurface     *surface,
                                      &shadow_right,
                                      &shadow_top,
                                      &shadow_bottom);
+
   gdk_win32_surface_set_shadow_width (surface,
                                       shadow_left,
                                       shadow_right,
@@ -1238,10 +1239,10 @@ gdk_win32_surface_layout_popup (GdkSurface     *surface,
   gdk_surface_layout_popup_helper (surface,
                                    width,
                                    height,
-                                   impl->shadow.left,
-                                   impl->shadow.right,
-                                   impl->shadow.top,
-                                   impl->shadow.bottom,
+                                   shadow_left,
+                                   shadow_right,
+                                   shadow_top,
+                                   shadow_bottom,
                                    monitor,
                                    &bounds,
                                    layout,
@@ -1261,9 +1262,7 @@ gdk_win32_surface_layout_popup (GdkSurface     *surface,
                                      final_rect.height);
     }
   else
-    {
-      gdk_win32_surface_move (surface, x, y);
-    }
+    gdk_win32_surface_move (surface, x, y);
 }
 
 static void
@@ -4417,9 +4416,9 @@ gdk_win32_surface_set_shadow_width (GdkSurface *window,
   if (impl->zero_shadow)
     return;
 
-  impl->shadow.left = left;
+  impl->shadow.left = left * impl->surface_scale;;
   impl->shadow.right = right * impl->surface_scale;
-  impl->shadow.top = top;
+  impl->shadow.top = top * impl->surface_scale;;
   impl->shadow.bottom = bottom * impl->surface_scale;
   impl->shadow_x = left + right;
   impl->shadow_y = top + bottom;
@@ -4555,7 +4554,7 @@ _gdk_win32_surface_request_layout (GdkSurface *surface)
   int scale = impl->surface_scale;
   RECT rect;
 
-  if (GDK_IS_TOPLEVEL (surface) && impl->drag_move_resize_context.native_move_resize_pending)
+  if (impl->drag_move_resize_context.native_move_resize_pending)
     {
       surface->width = impl->next_layout.configured_width;
       surface->height = impl->next_layout.configured_height;
@@ -4566,8 +4565,18 @@ _gdk_win32_surface_request_layout (GdkSurface *surface)
 
       impl->next_layout.configured_width = (rect.right - rect.left + scale - 1) / scale;
       impl->next_layout.configured_height = (rect.bottom - rect.top + scale - 1) / scale;
-      surface->x = rect.left / scale;
-      surface->y = rect.top / scale;
+
+      if (GDK_IS_TOPLEVEL (surface))
+        {
+          surface->x = rect.left / scale;
+          surface->y = rect.top / scale;
+        }
+      else if (GDK_IS_POPUP (surface))
+        {
+          gdk_win32_surface_get_geometry (surface,
+                                         &surface->x, &surface->y,
+                                          NULL, NULL);
+        }
     }
 }